package com.neuedu.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.neuedu.entity.Visitor;
import com.neuedu.mapper.VisitorMapper;
import com.neuedu.service.VisitorService;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * 就诊人信息表 服务层实现。
 *
 * @author Administrator
 * @since 2024-06-04
 */
@Service
public class VisitorServiceImpl extends ServiceImpl<VisitorMapper, Visitor> implements VisitorService {

    @Override
    public List<Visitor> list(Integer customId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("customer_id", customId);
        return this.list(wrapper);
    }

    @Override
    public boolean add(String name, String idCard, Integer type, String phone, Integer openId) {
        int i = Integer.valueOf(String.valueOf(idCard.charAt(16)));
        LocalDate date = LocalDate.parse(idCard.substring(6, 14), DateTimeFormatter.ofPattern("yyyyMMdd"));

        Visitor visitor = new Visitor(
                name,
                type,
                idCard,
                phone,
                openId,
                i % 2,
                Date.valueOf(date)
        );
        return this.save(visitor);
    }
}
